//
//  PosterCollectionViewCell.m
//  时光电影项目
//
//  Created by 墨狂之逸才 on 15/7/24.
//  Copyright (c) 2015年 墨狂之逸才. All rights reserved.
//

#import "PosterCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "UIViewExt.h"
#define Kheight  [UIScreen mainScreen].bounds.size.height
#define kwidth  [UIScreen mainScreen].bounds.size.width


@implementation PosterCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
       
        [self _creatSubview];
    }
    
    return self;
}

#pragma mark - 创建海报页面里的内容，子视图
- (void)_creatSubview
{
    _imageView = [[UIImageView alloc]initWithFrame:CGRectMake((self.width-self.width*0.9)/2, (self.height-self.height*0.9)/2, self.width*0.9, self.height*0.9)];
    _imageView.hidden = NO;
    [self.contentView addSubview:_imageView];
    
    
    //从xib获取detailView
    
    NSBundle *bundle = [NSBundle mainBundle];
    
    NSArray *views = [bundle loadNibNamed:@"PosterDetailView" owner:self options:nil];
    
    _detailView = [views lastObject];
    
    
    //错误写法，这是用alloc方法来创建的，我们的要求是用xib文件来加载的
//    _detailView = [[PosterDetailView alloc]initWithFrame:CGRectMake((self.width-self.width*0.9)/2, (self.height-self.height*0.9)/2, self.width*0.9, self.height*0.9)];

     _detailView.frame = CGRectMake((self.width-self.width*0.9)/2, (self.height-self.height*0.9)/2, self.width*0.9, self.height*0.9);
    
    _detailView.hidden = YES;
    
    [self.contentView addSubview:_detailView];
    
    
}


- (void)setModal:(MovieModal *)modal
{
    _modal = modal;
    
    _detailView.modal = modal;
    
    [self setNeedsLayout];
}



- (void)layoutSubviews
{
    
    NSString *str = [_modal.images objectForKey:@"large"];
    
    [_imageView sd_setImageWithURL:[NSURL URLWithString:str]];

    
}

#pragma mark - 翻页效果
- (void)flipView
{
    
    UIViewAnimationOptions option = isLeft?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;
    
    isLeft = !isLeft;
    
    [UIView transitionWithView:self duration:0.5 options:option animations:nil completion:nil];
    
    _detailView.hidden = !_detailView.hidden;
    _imageView.hidden = !_imageView.hidden;
  
    
}


@end
